const {User} = require("../../models/User");

module.exports = async (req, res) => {
    const userId = req.query.user_id;
    var myfollows =  [];
    try{
       const folRes = await User.findOne({user_id:userId},{follows:1,_id:0}).lean();
       let followlen = folRes.follows.length;
       for(let i=0;i<followlen;i++){
        var isFollow = false;
        const item = await User.findOne({user_id:folRes.follows[i].user_id},
            {user_id:1,nickname:1,sex:1,avatar:1,signature:1}).lean();
        const follow = await User.findOne({user_id:userId,"follows.user_id": item.user_id});
        if(follow){
            isFollow = true; 
            }
        item.isFollow = isFollow;
        myfollows.push(item);
        }
       res.send({errCode:"1",msg:"请求成功",data:{myfollows:myfollows}})
    }catch(e){
        console.log(e);
        res.status(400).send({errCode:"1",msg:"请求错误"})
    }
}